package test2;

/**
 * Test2_19
 */
public class Test2_19 {

  public static void main(String[] args) {
    printPascalTriangle(5);
  }

  /**
   * 输出指定行数的杨辉三角形
   * 
   * @param row 要输出的行数
   */
  public static void printPascalTriangle(int row) {
    int[] numbers = new int[row + 1];

    for (int i = 1, space = row - 1; i <= row; i++, space--) {
      // 输出每行空格
      for (int j = 0; j < space; j++) {
        System.out.print(" ");
      }

      numbers[1] = numbers[i] = 1;
      for (int j = i - 1; j > 1; j--) {
        numbers[j] += numbers[j - 1];
      }

      for (int j = 1; j <= i; j++) {
        System.out.print(numbers[j] + " ");
      }
      System.out.println();
    }
  }
}